package com.zhangxun.util;


import com.sun.org.apache.bcel.internal.generic.RETURN;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.authority.SimpleGrantedAuthority;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;


import javax.servlet.http.HttpServletRequest;
import java.util.List;

public class SecurityUtil {

    private SecurityUtil(){}

    public static Authentication getAuthentication(){
        Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
        return authentication;
    }

    public static List<SimpleGrantedAuthority> getAuthorities(){
        List<SimpleGrantedAuthority> authorities = (List<SimpleGrantedAuthority>) getAuthentication().getAuthorities();
        return authorities;
    }

    public static Long getUserId(){

        String userId = getAuthentication().getPrincipal().toString();

        return Long.valueOf(userId);
    }

    public static String getWxUserId(){

        return getAuthentication().getPrincipal().toString();


    }

}
